<template>
  <div :ref="ref" :style="{width: '100%', height: '100%' }" />
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'StorehouseChart',
  props: {
    data: {
      required: true,
      type: Array,
      default: function() {
        return []
      }
    },
    title: {
      required: true,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ref: 'AssetChart' + Math.floor(Math.random() * 1000000)
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    init() {
      const that = this
      const myChart = echarts.init(this.$refs[this.ref])
      const option = {
        title: {
          text: that.title
          // textStyle: {
          //   fontSize: 20
          // }
        },
        grid: {
          x: 25,
          y: 0,
          left: 45,
          right: 15
        },
        tooltip: {
          trigger: 'item'
        },
        series: [
          {
            // name: '租用率',
            type: 'pie',
            radius: '60%',
            center: ['50%', '60%'],
            label: {
              normal: {
                formatter: '{b}\n{d}%',
                textStyle: {
                  fontWeight: 'normal',
                  fontSize: 15
                }
              }
            },
            data: that.data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
      myChart.setOption(option)
    }
  }
}
</script>

<style>
</style>
